package cn.cqone.crm.service.impl;

import cn.cqone.crm.domain.Dictionary;
import cn.cqone.crm.domain.Employee;
import cn.cqone.crm.domain.Tenant;
import cn.cqone.crm.mapper.DictionaryMapper;
import cn.cqone.crm.mapper.EmployeeMapper;
import cn.cqone.crm.mapper.TenantMapper;
import cn.cqone.crm.query.DictionaryQuery;
import cn.cqone.crm.service.DictionaryService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary,Long, DictionaryQuery>
implements DictionaryService {
    @Autowired
    private DictionaryMapper dictionaryMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private TenantMapper tenantMapper;
    @Override
    public int add(Dictionary obj) {
        Employee employee =(Employee) SecurityUtils.getSubject().getPrincipal();
        Employee byName = employeeMapper.findByName(employee.getUsername());
        Long id = employee.getTenant().getId();
        Tenant byId = tenantMapper.findById(id);
        obj.setTenant(byId);
        return super.add(obj);
    }
}
